--- a/main.c	2008-03-01 21:01:41.000000000 +0100
+++ b/main.c	2008-03-04 18:55:10.933488013 +0100
@@ -82,6 +82,7 @@
 #ifdef ICONV_OPTION
 extern iconv_t ic_send;
 #endif
+extern int default_af_hint;
 
 uid_t our_uid;
 int local_server = 0;
@@ -381,6 +382,23 @@
 			*t++ = '\0';
 		}
 
+#ifdef AF_INET
+                if (default_af_hint == AF_INET) {
+                    if (strncmp(cmd, "ssh", 3) == 0 || strstr(cmd, "/ssh") != NULL) {
+                        /* we're using ssh so we can add a -4 option */
+                        args[argc++] = "-4";
+                    }
+                }
+#endif
+#ifdef AF_INET6
+                if (default_af_hint == AF_INET6) {
+                    if (strncmp(cmd, "ssh", 3) == 0 || strstr(cmd, "/ssh") != NULL) {
+                        /* we're using ssh so we can add a -6 option */
+                        args[argc++] = "-6";
+                    }
+                }
+#endif
+
 		/* check to see if we've already been given '-l user' in
 		 * the remote-shell command */
 		for (i = 0; i < argc-1; i++) {
